package cz.data.domain.market.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import cz.data.common.annotation.DataInner;
import cz.data.common.base.TableDataResponse;
import cz.data.common.core.DataSelectOption;
import cz.data.domain.market.model.dto.TableApiSettings;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class UiController {
    private static final List<DataSelectOption> tableOperateOptions;
    private static final List<DataSelectOption> tableAccessOptions;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取数据表操作接口下拉框选项")
    @GetMapping("/table/operate/options")
    public TableDataResponse<DataSelectOption> tableOperateOptions() {
        return new TableDataResponse<>(tableOperateOptions);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取数据表访问控制下拉框选项")
    @GetMapping("/table/access/options")
    public TableDataResponse<DataSelectOption> tableAccessOptions() {
        return new TableDataResponse<>(tableAccessOptions);
    }

    static {
        tableOperateOptions = Arrays.stream(TableApiSettings.Operate.values())
                .map(e -> new DataSelectOption(e.getValue(), e.getTitle(), e.getValue()))
                .collect(Collectors.toList());
        tableAccessOptions = Arrays.stream(DataInner.Access.values())
                .map(e -> new DataSelectOption(e.getValue(), e.getTitle(), e.getValue()))
                .collect(Collectors.toList());
    }
}
